<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>添加试题</title>
<%@include file="../core/head.jsp"%>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" href="${ctx}/css/core.css" type="text/css">
<link rel="stylesheet" href="${ctx}/css/exam.css" type="text/css">
<link rel="stylesheet" href="${ctx}/css/buttons.css" type="text/css">
<link rel="stylesheet" href="${ctx}/css/table.css" type="text/css">
<link rel="stylesheet" href="${ctx}/js/jquery-ui-1.10.3/css/ui-lightness/jquery-ui-1.10.3.custom.css" type="text/css">
<style type="text/css">

.ui-dialog ul li { margin: .3em; }
.validateTips { border: 1px solid transparent; padding: 0.3em; }

</style>
<script type="text/javascript"	src="${ctx }/js/jquery-ui-1.10.3/js/jquery-ui-1.10.3.custom.js"></script>
<script type="text/javascript" src="${ctx }/js/FusionCharts.js"></script>
<script type="text/javascript">
 
var ready = {};
function showPapers( ){
	var type = $("#type").val();
	if(ready["PAPER-"+type]){
		return;
	}
	var url = "${ctx}/exam/findPapers.action";
	$.post(url,{"paper.type":type} ,
	function listPaper(paper){
 
		var div = $("#choosepaper");
		div.empty();
		if(paper.length<=0){
			div.append("<div>试题库为空，是否执行【添加试题】操作？</div>")
			
		}else{
			
			for(var i = 0;i<paper.length;i++){
				var p = paper[i];
				var item = $("<li><label><input type='radio' name='paperName' value='"+p.id+"'/> <span>"+p.title+"</span></label></li>");
				div.append(item);
			}
		}
		ready["PAPER-"+type]=true;
	});
}
 
var myChart;
$(function(){
	showPapers();
	myChart= new FusionCharts("${ctx}/charts/Doughnut3D.swf", "myChartId", 500, 300);
	getStaticInfos();
});

function getStaticInfos(){
	var type = $("#type").val();
	var url = "${ctx}/exam/getPaperInfo.action";
	$.post(url,{"paper.type":type} ,
	function showChart(staticInfos){
	var dataxml = "<chart   decimals='1' showLabels='1' useRoundEdges='1' formatNumberScale='0' baseFont='宋体' showValues='1' caption='试题分布' pieSliceDepth='20' baseFontSize='12'     pieRadius='130' >";
	for(i in staticInfos){
		var info = staticInfos[i];
		dataxml=dataxml+"<set name='" +info.title+"' value='"+info.num+"'  />";
	 	  
	 }
	
	dataxml= dataxml+ "</chart>";
	myChart.setDataXML(dataxml);    
	myChart.render("chartdiv");
	 
	});
	
}


function bulkImport(){
	$("#editQuestions").val("false");
	$("#mainForm").submit();
}
function bulkModify(){
	$( "#dialog-form" ).dialog( "open" );
}

 $(function(){
	 $( "#dialog-form" ).dialog({
	      autoOpen: false,
	      height: 300,
	      width: 350,
	      modal: true,
	      buttons: {
	        "确定": function() {
	        	var inp = $("#choosepaper input");
	         	var qid = inp.find(":checked").val(); 
	         	if(qid){
		          	$("#questionInfoId").val(qid);
		          	$("#editQuestions").val("true");
		        	$( this ).dialog( "close" );
	    	    	$("#mainForm").submit();
	         	}else if(inp.size()<=0){
	         		$( this ).dialog( "close" );
	         		bulkImport();
	         	}else{
	         		$("#errorinfo").show();
	         	}
	        },
	        "取消": function() {
	        	$("#questionInfoId").val("");
	        	$( this ).dialog( "close" );
	        }
	      },
	      close: function() {
	    	  $("#errorinfo").hide();
	        }
	    });
	 
 })

</script>

</head>

<body>
<%@include file="top.jsp"%>
 
<div class="width center menuPanel radius">
	<div class="upload center " align="center">
		<div  style="width:480px; margin-top: -20px; " class="left">
			<div id="chartdiv" ></div>
		</div>
		
		<div class="right" style="width: 500px;  padding:30px 0;" >
		<form id="mainForm" action="${ctx }/exam/addQuestion.action" method="post">
			<input type="hidden" id="questionInfoId" name="questionInfo.id" value=""/>
			<input type="hidden" id="editQuestions" name="editQuestions" value="false"/>
			<div class="table">
				 题库类型:  
				<select id="type" name="paper.type" onchange="showPapers()">
					<z:dic code="" isType="true" init="${paper.type}" />
				</select>
			</div>
				 
			 <div style="margin-top: 40px;">
				<a  onclick="bulkImport()" class="button green menuBut" >添加试题</a> 
				<a  onclick="bulkModify()" class="button orange menuBut">批量修改</a> 
				<a href="${ctx}/exam/searchQuestions.action" class="button blue menuBut" >查询</a> 
			</div> 
	 
			</form>
		 </div>
		<div class="clear"></div>

	</div>
</div>

	
	
	
<div id="dialog-form" title="选择修改的题库">
  <p id="errorinfo" class="validateTips" style="display: none;">请选择要修改的试题</p>
  <ul id="choosepaper">  </ul>
</div>
  



<%@include file="../core/bottom.jsp"%> 
	
</body>
</html>
